package com.situ.javase.day13.reflact;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.junit.Test;

public class Clinet {
	public static void main(String[] args) throws Exception {
		// 现在是new出具体数据库，如果有一天需要换成Oracle数据库，
		// 需要修改java源代码
//		AbstractDB db = new MySql();
//		db.getConnection();
//		MySql mySql = new MySql();
//		mySql.getConnection();
		
		FileInputStream fileInputStream = new FileInputStream("src/com/situ/javase/day13/reflact/db.properties");
		Properties properties = new Properties();
		properties.load(fileInputStream);
		String className = properties.getProperty("className");
		System.out.println(className); 
		Class clazz = Class.forName(className);
		// 如果类里面有无参构造方法，可以直接clazz.newInstance()
		// AbstractDB db = new MySql();
		AbstractDB db  = (AbstractDB) clazz.newInstance();
		db.getConnection();
	}
	
	@Test
	public void test() {
		String goodsName = "诺基亚原装5800耳机";
		String name = "HTC" + goodsName.substring(3);
		System.out.println(name);
	}
	
	
}
